#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int N=1e3+10,mod=1e9+7,po=13331;
int n,m;
int has(string a)
{
	int len=a.size();
	int sum=0;
	for(int i=0; i<len; ++i)
		sum=(sum*po+(int)a[i]-40)%mod;
	return sum;
}
struct data
{
	string op,ad;
	int a,b,c,d,e;
	int ha;
	bool f;
};
data q[N];
int get(string x,int p)
{
	int len=x.size(),sum=0;
	if(len>=2&&x[0]=='0')return -1;
	for(int i=0; i<len; ++i)
		sum=sum*10+(int)x[i]-'0';
	if(p==1)
		if(sum>255||sum<0)return -1;
	if(p==2)
		if(sum<0||sum>65535)return -1;
	return sum;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i)
	{
		cin>>q[i].op>>q[i].ad;
		int node1=q[i].ad.find(".");
		int node2=q[i].ad.find(".",node1+1);
		int node3=q[i].ad.find(".",node2+1);
		int node4=q[i].ad.find(":");
		if(node1==-1||node2==-1||node3==-1||node4==-1)
		{
			printf("ERR\n");
			continue;
		}
		//cout<<node1<<' '<<node2<<' '<<node3<<' '<<node4<<endl;
		string a=q[i].ad.substr(0,node1);
		string b=q[i].ad.substr(node1+1,node2-node1-1);
		string c=q[i].ad.substr(node2+1,node3-node2-1);
		string d=q[i].ad.substr(node3+1,node4-node3-1);
		string e=q[i].ad.substr(node4+1,q[i].ad.size()-node4);
		//cout<<get(a)<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
		if(a.size()==0||b.size()==0||c.size()==0||d.size()==0||e.size()==0)
		{
			printf("ERR\n");
			continue;
		}
		q[i].a=get(a,1);
		q[i].b=get(b,1);
		q[i].c=get(c,1);
		q[i].d=get(d,1);
		q[i].e=get(e,2);
		if(q[i].a==-1||q[i].b==-1||q[i].c==-1||q[i].d==-1||q[i].e==-1)
		{
			printf("ERR\n");
			continue;
		}
		if(q[i].op=="Server")
		{
			q[i].ha=has(q[i].ad);
			bool flag=1;
			for(int j=i-1; j>=1; j--)
			{
				if(q[j].op=="Server")
				{
					if(q[j].f==1&&q[j].ha==q[i].ha)
					{
						flag=0;
						break;
					}
				}
			}
			if(flag==0)
			{
				printf("FAIL\n");
				q[i].f=0;
				continue;
			}
			//cout<<q[i].ha<<endl;
			printf("OK\n");
			q[i].f=1;
		}
		if(q[i].op=="Client")
		{
			q[i].ha=has(q[i].ad);
			int flag=0;
			for(int j=i-1; j>=1; j--)
			{
				if(q[j].op=="Server")
				{
					if(q[j].f==1&&q[j].ha==q[i].ha)
					{
						flag=j;
						break;
					}
				}
			}
			if(flag==0)
			{
				printf("FAIL\n");
				continue;
			}
			//cout<<"gay"<<' '<<q[i].ha<<endl;
			printf("%d\n",flag);
		}
	}
	
	return 0;
}
